**This program makes a unique country-level on country variables dataset to match FTD and BEA codes


cd ""  /* PROJECT ROOT FOLDER */
global data "data"
global input "input"


use "$data/country_data_clean.dta", clear
keep if countrycode~=.
  *Keep largest population observation
duplicates tag countrycode, gen(dupes)
tab dupes
  sort countrycode pop gdp
  *browse country* pop pop_o gdp if dupes>=1
  *drop if pop or other vars missing
  drop if dupes>=1 & (pop==. | gdp==.) & (countrycode~=255 & countrycode~=266 & countrycode~=609 & countrycode~=610)
  *keep largest pop
    drop dupes
    duplicates tag countrycode, gen(dupes)
    bys countrycode: gen drop=1 if _n~=_N
    drop if drop==1 & dupes>=1
    drop dupes
    
save  "$data/country_data_unique.dta", replace
